#pragma once
#include "PinBaseVisitor.h"

class SymNode;

enum AssignOpType{
    EQUAL_ASSIGN=0,
    MUL_ASSIGN,
    DIV_ASSIGN,
    ADD_ASSIGN,
    SUB_ASSIGN,
    //ADD_AUTO_ASSIGN, //++
    //SUB_AUTO_ASSIGN, //--
    DEFINE_ASSIGN,//定义加赋值
};

void multiCallFunCtxReplace(bool isMultiFunCall, PinParser::RealCallFunContext* &ctx);

class ExprValue;

int FillExprByExpr(ExprValue* pSym, ExprValue* pSrcSyn, antlr4::ParserRuleContext *ctx, bool iswarn = true, AssignOpType op = EQUAL_ASSIGN);

class ExprVisitor : public PinBaseVisitor
{
public:
    virtual std::any visitDefvar(PinParser::DefvarContext *ctx) override;
    virtual std::any visitDefstvar(PinParser::DefstvarContext *ctx) override;
    virtual std::any visitDefglobal(PinParser::DefglobalContext *ctx) override;

    //virtual std::any visitGlobalblock(PinParser::GlobalblockContext *ctx) override;

    //virtual std::any visitAssign(PinParser::AssignContext *ctx) override;
    //virtual std::any visitAssginNoEnd(PinParser::AssginNoEndContext *ctx) override;

    //virtual std::any visitAssignBaseVar(PinParser::AssignBaseVarContext *ctx) override;

    virtual std::any visitAssignVar(PinParser::AssignVarContext *ctx) override;

    //virtual std::any visitAssignMapVar(PinParser::AssignMapVarContext *ctx) override;

    //virtual std::any visitAssignStructVar(PinParser::AssignStructVarContext *ctx) override;

	virtual std::any visitBlock(PinParser::BlockContext* ctx) override;

	//virtual std::any visitMainFun(PinParser::MainFunContext* ctx) override;
    //virtual std::any visitCallFun(PinParser::CallFunContext* ctx) override;
	virtual std::any visitProgram(PinParser::ProgramContext* ctx) override;

	virtual std::any visitFunction(PinParser::FunctionContext* ctx) override;


    virtual std::any visitArgument(PinParser::ArgumentContext *ctx) override;

    virtual std::any visitMultExpr(PinParser::MultExprContext *ctx) override;
    virtual std::any visitIntExpr(PinParser::IntExprContext *ctx) override;

    virtual std::any visitRemainderExpr(PinParser::RemainderExprContext* ctx) override;
    //virtual std::any visitVarExpr(PinParser::VarExprContext *ctx) override;

   // virtual std::any visitAutoAddExpr(PinParser::AutoAddExprContext *ctx) override;
    //virtual std::any visitAutoSubExpr(PinParser::AutoSubExprContext *ctx) override;

    virtual std::any visitAddExpr(PinParser::AddExprContext *ctx) override;
    virtual std::any visitSubExpr(PinParser::SubExprContext *ctx) override;
    virtual std::any visitDivExpr(PinParser::DivExprContext *ctx) override;
    virtual std::any visitFloatExpr(PinParser::FloatExprContext *ctx) override;
    virtual std::any visitStrExpr(PinParser::StrExprContext* ctx) override;
    virtual std::any visitRowStrExpr(PinParser::RowStrExprContext *ctx) override;
    virtual std::any visitParenthesesExpr(PinParser::ParenthesesExprContext *ctx) override;

    //virtual std::any visitHs_print(PinParser::Hs_printContext *ctx) override;

    virtual std::any visitFormat_string(PinParser::Format_stringContext *ctx) override;

    virtual std::any visitPrintExpr(PinParser::PrintExprContext *ctx);

    virtual std::any visitFormatPrintExpr(PinParser::FormatPrintExprContext *ctx);

    virtual std::any visitOutputExpr(PinParser::OutputExprContext *ctx) override;

    //virtual std::any visitRetExpr(PinParser::RetExprContext* ctx) override;

    //virtual std::any visitRetFunExpr(PinParser::RetFunExprContext *ctx) override;

    virtual std::any visitRetCode(PinParser::RetCodeContext* ctx);

    virtual std::any visitNoRetCallFun(PinParser::NoRetCallFunContext* ctx) override;

    virtual std::any visitWithRetCallFun(PinParser::WithRetCallFunContext* ctx) override;

    virtual std::any visitReturnCallFun(PinParser::ReturnCallFunContext* ctx) override;

    //virtual std::any visitAndExpr(PinParser::AndExprContext *ctx) override;
    //virtual std::any visitOrExpr(PinParser::OrExprContext *ctx) override;
    //virtual std::any visitNotExpr(PinParser::NotExprContext *ctx) override;

    virtual std::any visitNotExpr(PinParser::NotExprContext* ctx) override;
    //virtual std::any visitAndExpr(PinParser::AndExprContext* ctx) override;
    virtual std::any visitOrExpr(PinParser::OrExprContext* ctx) override;

    virtual std::any visitAndExpr(PinParser::AndExprContext* ctx) override;

    virtual std::any visitUnequalExpr(PinParser::UnequalExprContext *ctx) override;
    virtual std::any visitEqualExpr(PinParser::EqualExprContext *ctx) override;

    //virtual std::any visitBoolVarExpr(PinParser::BoolVarExprContext* context);

    virtual std::any visitGreaterExpr(PinParser::GreaterExprContext *ctx) override;
    virtual std::any visitLessExpr(PinParser::LessExprContext *ctx) override;
    virtual std::any visitLessEqualExpr(PinParser::LessEqualExprContext *ctx) override;
    virtual std::any visitGreaterEqualExpr(PinParser::GreaterEqualExprContext *ctx) override;


    //virtual std::any visitBoolAssign(PinParser::BoolAssignContext *ctx) override;
    virtual std::any visitBoolValueExpr(PinParser::BoolValueExprContext *ctx) override;
    //virtual std::any visitParenthesesBoolExpr(PinParser::ParenthesesBoolExprContext *ctx) override;

    //virtual std::any visitRealCallFun(PinParser::RealCallFunContext* ctx)override;


    std::any visitRealCallFun(PinParser::RealCallFunContext* ctx, PinParser::WithRetCallFunContext* ctxParent, int flag);

    std::any visitRealCallNormalFun(PinParser::RealCallFunContext* ctx, PinParser::WithRetCallFunContext* ctxParent, int flag);
    std::any visitRealCallNormalFun(PinParser::RealCallFunContext* ctx, PinParser::WithRetCallFunContext* ctxParent, \
                                                 std::string funName, PinParser::ArgumentListContext* pArglist, int flag);


    //virtual std::any visitNormalFun(PinParser::NormalFunContext* ctx) override;

    virtual std::any visitIf(PinParser::IfContext* ctx) override;
    virtual std::any visitZif(PinParser::ZifContext* ctx) override;
    virtual std::any visitQt(PinParser::QtContext* ctx) override;

    //virtual std::any visitFor(PinParser::ForContext* ctx) override;

    virtual std::any visitForState(PinParser::ForStateContext* ctx) override;

    virtual std::any visitWhileState(PinParser::WhileStateContext* ctx) override;

    virtual std::any visitForInState(PinParser::ForInStateContext* ctx) override;

    //virtual std::any visitForinit(PinParser::ForinitContext* ctx) override;

    virtual std::any visitNegationExpr(PinParser::NegationExprContext* ctx) override;

    virtual std::any visitForinc(PinParser::ForincContext* ctx) override;

    virtual std::any visitBreak(PinParser::BreakContext* ctx) override;

    virtual std::any visitContinue(PinParser::ContinueContext* ctx) override;

    virtual std::any visitDeclareStruct(PinParser::DeclareStructContext *ctx) override;

    virtual std::any visitPinvar(PinParser::PinvarContext *ctx) override;

    std::any visitPinvar(PinParser::PinvarContext *ctx, bool isRefGet = false, ExprValue * assignExpr= nullptr, AssignOpType op = EQUAL_ASSIGN);


    virtual std::any visitAssignStOne(PinParser::AssignStOneContext *ctx) override;

    //virtual std::any visitAssignListVar(PinParser::AssignListVarContext *ctx) override;

    virtual std::any visitList(PinParser::ListContext *ctx) override;

    virtual std::any visitMap(PinParser::MapContext *ctx) override;

    //virtual std::any visitMapvalue(PinParser::MapvalueContext *ctx) override;

    virtual std::any visitStRightVar(PinParser::StRightVarContext *ctx) override;

    virtual std::any visitCallFunExpr(PinParser::CallFunExprContext* ctx) override;

    virtual std::any visitCharValueExpr(PinParser::CharValueExprContext *ctx) override;

    virtual std::any visitStMemVar(PinParser::StMemVarContext *ctx) override;

    virtual std::any visitFmtString(PinParser::FmtStringContext* ctx) override;

    virtual std::any visitLogRevExpr(PinParser::LogRevExprContext* ctx) override;

    virtual std::any visitLogAndExpr(PinParser::LogAndExprContext* ctx) override;

    virtual std::any visitLogOrExpr(PinParser::LogOrExprContext* ctx) override;

    virtual std::any visitLogXorExpr(PinParser::LogXorExprContext* ctx) override;

    //virtual std::any visitAssignAutoAdd(PinParser::AssignAutoAddContext *ctx) override;

    //virtual std::any visitMultiFunAccessExpr(PinParser::MultiFunAccessExprContext *ctx) override;

    virtual std::any visitSignalState(PinParser::SignalStateContext *ctx) override;

    //virtual std::any visitBasevar(PinParser::BasevarContext* ctx) override;

    virtual std::any visitPinAutoAddSub(PinParser::PinAutoAddSubContext *ctx) override;

    virtual std::any visitPinFlag(PinParser::PinFlagContext *ctx) override;

    virtual std::any visitInExpr(PinParser::InExprContext* ctx) override;

    virtual std::any visitNotinExpr(PinParser::NotinExprContext *ctx) override;

    virtual std::any visitForwalk(PinParser::ForwalkContext *ctx) override;

private:

    //int assignStructMem(PinParser::StructMemContext* pStMem, SymNode* pSrvVar, antlr4::ParserRuleContext* ctx);
    int assignStructMem(SymNode* pSym, PinParser::StMemVarContext* pStructMem, SymNode* pSrvVar, antlr4::ParserRuleContext* ctx);

    //int assignList(PinParser::AccesslistContext* pList, SymNode* pSrvVar, antlr4::ParserRuleContext *ctx);
    //int assignMap(PinParser::AccessmapContext* pList, SymNode* pSrvVar, antlr4::ParserRuleContext *ctx);
    std::any visitCallQtFun(PinParser::RealCallFunContext* ctx, PinParser::WithRetCallFunContext* ctxParent, int flag);
    std::any visitCallQtFun(PinParser::RealCallFunContext* ctx, PinParser::WithRetCallFunContext* ctxParent, ExprValue& objExpr, \
         std::string funName, PinParser::ArgumentListContext* pArglist, bool isBaoFunCall, int flag);


};

